/**
 * Created by admin on 2017/10/26.
 */
$(document).ready(function () {
    var compare = function (obj1, obj2) {
        var val1 = obj1.ope_id;
        var val2 = obj2.ope_id;
        if (val1 < val2) {
            return -1;
        } else if (val1 > val2) {
            return 1;
        } else {
            return 0;
        }
    };

    var VAL = {
    	NORMAL      : "0000000"  ,
    	EVT_USER    : $("#userId").text(),
    	T_FDPAPLYWO : "FDPAPLYWO",
    	T_FBPBISOPE : "FBPBISOPE",
    	T_FBPBISTOL : "FBPBISTOL",
    	T_FBPSWHPTH : "FBPSWHPTH",
    	T_FBPBISDAT : "FBPBISDAT",
    	T_FBPMDLDEF : "FBPMDLDEF",
    	T_FIPINQSHT : "FIPINQSHT",
    	T_FPPMOVEOUT: "FPPMOVEOUT",
    	T_MIPINQMTRL: "MIPINQMTRL",
        T_FBPBISPTH : "FBPBISPTH",
        T_MSPLINEWO : "MSPLINEWO",
        DISABLED_ATTR: {
            'disabled': true
        },
        ENABLED_ATTR: {
            'disabled': false
        }
    };
    
    var domObj = {
        buttons : {
            $move_out_btn : $("#move_out_btn"),
            $clean_btn    : $("#clean_btn")
        },
        
        $bayIdSel      : $("#bayIdSel"),
        $opeIdSel      : $("#opeIdSel"),
        $toolIdSel     : $("#toolIdSel"),
        $woCateSel     : $("#woCateSel"),
        $woIdSel       : $("#woIdSel"),
        $prdSeqIdTxt   : $("#prdSeqIdTxt"),
        $radioOK       : $("#radioOK"),
        $radioNG       : $("#radioNG"),
        $reworkSel     : $("#reworkSel"),
        $defectCodeSel : $("#defectCodeSel"),
        $remarkTxt     : $("#remarkTxt"),
        $prdGradeSel   : $("#prdGradeSel"),
        
        grids : {
            $prodListDiv : $("#prodListDiv"),
            $prodListGrd : $("#prodListGrd"),
            $prodListPg  : $("#prodListPg"),
            $mtrlListDiv : $("#mtrlListDiv"),
            $mtrlListGrd : $("#mtrlListGrd"),
            $mtrlListPg  : $("#mtrlListPg")
        },
        
        dialogs: {
            $gradeDialog : $("#gradeDialog"),
            $gradeDialog_gradeGroupSel : $("#gradeDialog_gradeGroupSel"),
            $gradeDialog_gradeListDiv : $("#gradeDialog_gradeListDiv"),
            $gradeDialog_gradeListGrd : $("#gradeDialog_gradeListGrd"),
            $gradeDialog_gradeListPg : $("#gradeDialog_gradeListPg"),
            $gradeDialog_sureBtn : $("#gradeDialog_sureBtn"),
            
            $defectDialog : $("#defectDialog"),
            $defectDialog_defectTypeSel : $("#defectDialog_defectTypeSel"),
            $defectDialog_defectListDiv : $("#defectDialog_defectListDiv"),
            $defectDialog_defectListGrd : $("#defectDialog_defectListGrd"),
            $defectDialog_defectListPg : $("#defectDialog_defectListPg"),
            $defectDialog_sureBtn : $("#defectDialog_sureBtn"),
        }
    };
    
    /**
     * grid  initialization
     */
    var iniGridInfo = function() {
        domObj.grids.$prodListGrd.jqGrid({
	        url: "",
	        datatype: "local",
	        mtype: "POST",
	        autowidth: true,
	        shrinkToFit: false,
	        resizable: true,
	        loadonce: true,
	        viewrecords: true,
	        rownumbers: true,
	        rowNum: 20,
	        emptyrecords: true,
	        colModel: [
	            {
	                name: 'prd_seq_id',
	                index: 'prd_seq_id',
	                label: SHEET_ID_TAG,
	                width: 150
	            },  {
	                name: 'prd_stat',
	                index: 'prd_stat',
	                label: PRD_STAT_TAG,
	                width: 100
	            },{
	                name: 'prd_grade',
	                index: 'prd_grade',
	                label: PRD_GRADE_TAG,
	                width: 100
	            }, {
	                name: 'lot_id_fk',
	                index: 'lot_id_fk',
	                label: LOT_ID_TAG,
	                width: 150
	            }, {
	                name: 'wo_id_fk',
	                index: 'wo_id_fk',
	                label: WO_ID_TAG,
	                width: 150
	            },{
	                name: 'mdl_id_fk',
	                index: 'mdl_id_fk',
	                label: MDL_ID_TAG,
	                width: 200
	            }, {
	                name: 'path_id_fk',
	                index: 'path_id_fk',
	                label: PATH_ID_TAG,
	                width: 100
	            }, {
	                name: 'path_ver_fk',
	                index: 'path_ver_fk',
	                label: PATH_VER_TAG,
	                width: 100
	            }, {
	                name: 'ope_id_fk',
	                index: 'ope_id_fk',
	                label: OPE_ID_TAG,
	                width: 100
	            }, {
	                name: 'ope_no_fk',
	                index: 'ope_no_fk',
	                label: OPE_NO_TAG,
	                width: 100
	            },{
	                name: 'ope_ver_fk',
	                index: 'ope_ver_fk',
	                label: OPE_VER_TAG,
	                width: 100
	            }, {
	                name: 'proc_id_fk',
	                index: 'proc_id_fk',
	                label: PROC_ID_TAG,
	                width: 100
	            },{
	                name: 'tool_id_fk',
	                index: 'tool_id_fk',
	                label: TOOL_ID_TAG,
	                width: 100
	            },{
	            	name: 'logon_timestamp',   
	            	index: 'logon_timestamp',
	            	label: LOGON_TIMESTAMP_TAG, 
	            	width: 180}],
	        pager: "#prodListPg"
	    });
        domObj.grids.$mtrlListGrd.jqGrid({
	        url: "",
	        datatype: "local",
	        mtype: "POST",
	        autowidth: true,
	        shrinkToFit: true,
	        resizable: true,
	        loadonce: true,
	        viewrecords: true,
	        rownumbers: true,
	        rowNum: 20,
	        emptyrecords: true,
	        colModel: [
	            {
	                name: 'mtrl_cate',
	                index: 'mtrl_cate',
	                label: MTRL_CATE_TAG,
	                width: 100
	            },  {
	                name: 'mtrl_prod_id_fk',
	                index: 'mtrl_prod_id_fk',
	                label: MTRL_ID_TAG,
	                width: 200
	            },{
	                name: 'mtrl_batch',
	                index: 'mtrl_batch',
	                label: MTRL_LOT_ID_TAG,
	                width: 200
	            }, {
	                name: 'mtrl_qty',
	                index: 'mtrl_qty',
	                label: MTRL_QTY_TAG,
	                width: 100
	            }],
	        pager: "#mtrlListPg"
	    });
        domObj.dialogs.$defectDialog_defectListGrd.jqGrid({
            url: "",
            datatype: "local",
            mtype: "POST",
            autowidth: false,
            shrinkToFit: true,
            resizable: true,
            loadonce: true,
            viewrecords: true,
            rownumbers: true,
            rowNum: 20,
            emptyrecords: true,
            colModel: [
                {
                    name: 'data_id',
                    index: 'data_id',
                    label: DEF_CODE_TAG,
                    width: 180
                }, {
                    name: 'data_ext',
                    index: 'data_ext',
                    label: DEF_DESC_TAG,
                    width: 350
                }],
            pager: "#defectDialog_defectListPg"
        });
        domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid({
        	url: "",
        	datatype: "local",
        	mtype: "POST",
        	autowidth: true,
        	shrinkToFit: true,
        	resizable: true,
        	loadonce: true,
        	viewrecords: true,
        	rownumbers: true,
        	rowNum: 20,
        	emptyrecords: true,
        	colModel: [
        	    {
        	    	name: 'prd_grade',
        	    	index: 'prd_grade',
        	    	label: PRD_GRADE_TAG,
        	    	width: 180
	            }, {
	            	name: 'grade_desc',
	            	index: 'grade_desc',
	            	label: PRD_GRADE_DSC_TAG,
	            	width: 350
                }],
            pager: "#gradeDialog_gradeListPg"
        });
	};
    
    /**
     * All tool functions
     * @type {Object}
     */
    var toolFunc = {
    	resizeFnc : function(){
            var offsetBottom, grdDivWidth;
            grdDivWidth = $(".divTop").width();
            offsetBottom = $(window).height() - domObj.grids.$prodListDiv.offset().top;
            
            //prodList设置
            domObj.grids.$prodListDiv.width(grdDivWidth);
            domObj.grids.$prodListDiv.height(offsetBottom*0.35);
            domObj.grids.$prodListGrd.setGridWidth(grdDivWidth);
            domObj.grids.$prodListGrd.setGridHeight(offsetBottom*0.35-51);
            
            //mtrlList设置
            domObj.grids.$mtrlListDiv.width(grdDivWidth);
            domObj.grids.$mtrlListDiv.height(offsetBottom*0.65);
            domObj.grids.$mtrlListGrd.setGridWidth(grdDivWidth);
            domObj.grids.$mtrlListGrd.setGridHeight(offsetBottom*0.65-51);
    	},
        initBayArea : function(){
            comAddValueByDataCateFnc("#bayIdSel", "AREA", "data_ext", "data_desc", true);
        },
        initWoCate: function(){
            comAddValueByDataCateFnc("#woCateSel", "WOCT", "data_ext", "data_desc", true);
        },
        iniWoIdSel : function(){
            var wo_cate = $.trim(domObj.$woCateSel.val());
            var inObj = {
                trx_id : VAL.T_FDPAPLYWO,
                action_flg : "Q",
                iary : [{
                    wo_cate  : wo_cate
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                var oaryA = outObj.oary;
                oaryA.sort(compare);
                SelectDom.addSelectArr(domObj.$woIdSel, oaryA, "wo_id","wo_id","",true);
            }
        },
        iniOpeIdSel : function(){
            var inObj = {
                trx_id : VAL.T_FBPBISOPE,
                action_flg : "L"
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                var oaryA = outObj.oary;
                oaryA.sort(compare);
                toolFunc.addSelectOpe(domObj.$opeIdSel, oaryA, "ope_id","ope_id","ope_dsc",true);
            }
        },
        iniToolIdSel : function(){
            var bay_id  = $.trim(domObj.$bayIdSel.val());
            var ope_id = $.trim(domObj.$opeIdSel.val());
            if(bay_id==""||ope_id==""){
                return;
            }
            var inObj = {
                trx_id : VAL.T_FBPBISTOL,
                action_flg : "M",
                iary : [{
                    bay_id      : bay_id,
                    ope_id_fk   : ope_id
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                SelectDom.addSelectArr_(domObj.$toolIdSel, outObj.oary, "tool_id","tool_id","tool_dsc",true);
            }
        },
        /**
         * 根据屏体代码的工艺、站点信息初始化重工工艺
         */
        iniReworkPathSel : function(){
        	var rowIds = domObj.grids.$prodListGrd.jqGrid('getDataIDs');
    		if(rowIds.length <= 0){
    			showErrorDialog("","请输入需要出账的屏体代码，并按回车键获取屏体信息！");
    			return false;
    		}
    		
    		var rowData = domObj.grids.$prodListGrd.jqGrid('getRowData',rowIds[0]);
            var inObj = {
                trx_id: VAL.T_FBPSWHPTH,
                action_flg: 'Q',
                iary: [{
                    fr_path_id_fk  : rowData['path_id_fk'],
                    fr_path_ver_fk : rowData['path_ver_fk'],
                    fr_ope_no_fk   : rowData['ope_no_fk'],
                    swh_typ: 'R'
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                if(outObj.swh_avl_flg=='Y'){
                    outObj.oary.sort(compare);
                    var options = [];
                    for(var i=0;i<outObj.oary.length;i++){
                        options[i] = "<option value ="+ outObj.oary[i]['swh_path_id_fk'] 
                        	+ "@" + outObj.oary[i]['swh_path_ver_fk']
                        	+ "@" + outObj.oary[i]['swh_id']
                        	+ "@" + outObj.oary[i]['swh_typ'] 
                        	+ ">" + outObj.oary[i]['swh_path_id_fk']+":"+ outObj.oary[i]['swh_dsc']+ "</option>";
                    }
                    domObj.$reworkSel.append(options.join(""));
                    domObj.$reworkSel.select2({
                        theme : "bootstrap"
                    });
                }
            }
        },
    	/***************************初始化等级Dialog***************************/
    	iniDefectDialogFunc : function(){
		      /*****
	        当多次弹出对话框的同时也会多次绑定click事件。
	        解决办法: 在show Dialog时将click unbind全部掉
	                  然后再绑定，这样就只剩下一个click事件了。
	      **********/
    		domObj.dialogs.$defectDialog.unbind('shown.bs.modal');
		    domObj.dialogs.$defectDialog_sureBtn.unbind('click');
    		domObj.dialogs.$defectDialog_defectTypeSel.select2({
    			theme : "bootstrap",
    	        width : $(window).width()* 0.12
    	    });
      		domObj.dialogs.$defectDialog_sureBtn.bind('click', btnFunc.defect_sure_func);
		    domObj.dialogs.$defectDialog.modal('show');
    	},
    	iniDefectInfo : function(){
            var inObj = {
                trx_id: VAL.T_FBPBISDAT,
                action_flg: "1",
                distinct_item : "EXT_2",
                iary: [{
                    data_cate : "DFCT"
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	SelectDom.addSelectArr(domObj.dialogs.$defectDialog_defectTypeSel, outObj.oaryB, "distinct_data", "distinct_data", true, true);
            }else{
            	return false;
            }
            if(!toolFunc.iniDefectListInfo()){
            	return false;
            }
            return true;
    	},
    	iniDefectListInfo : function(){
            var inObj = {
                trx_id: VAL.T_FBPBISDAT,
                action_flg: "Q",
                iary: [{
                    data_cate : "DFCT",
                    ext_2 : $.trim(domObj.dialogs.$defectDialog_defectTypeSel.val())
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                setGridInfo(outObj.oary, "#defectDialog_defectListGrd");
            }
    	},
    	/***************************初始化等级Dialog***************************/
    	iniGradeDialogFunc : function(){
		      /*****
	        当多次弹出对话框的同时也会多次绑定click事件。
	        解决办法: 在show Dialog时将click unbind全部掉
	                  然后再绑定，这样就只剩下一个click事件了。
	      **********/
    		domObj.dialogs.$gradeDialog.unbind('shown.bs.modal');
		    domObj.dialogs.$gradeDialog_sureBtn.unbind('click');
    		domObj.dialogs.$gradeDialog_gradeGroupSel.select2({
    			theme : "bootstrap",
    	        width : $(window).width()* 0.12
    	    });
      		domObj.dialogs.$gradeDialog_sureBtn.bind('click', btnFunc.grade_sure_func);
		    domObj.dialogs.$gradeDialog.modal('show');
    	},
        /**
         * 根据屏体的产品代码、OK/NG选择，获取等级信息
         */
        iniGradeInfo : function(){
    		SelectDom.initWithSpace(domObj.dialogs.$gradeDialog_gradeGroupSel);
    		domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid("clearGridData");
        	var rowIds = domObj.grids.$prodListGrd.jqGrid('getDataIDs');
    		if(rowIds.length <= 0){
    			showErrorDialog("","请输入需要出账的屏体代码，并按回车键获取屏体信息！");
    			return false;
    		}
    		var rowData = domObj.grids.$prodListGrd.jqGrid('getRowData',rowIds[0]);
            var okng = "NG";
            if(domObj.$radioOK.attr("checked") == "checked") {
                okng = "OK";
                SelectDom.initWithValTxt(domObj.$prdGradeSel, rowData['prd_grade'], rowData['prd_grade']);
            }else{
            	SelectDom.initWithSpace(domObj.$prdGradeSel, "", "");
            }
            var inObj = {
                trx_id: VAL.T_FBPMDLDEF,
                action_flg: "M",
                iary: [{
                    mdl_id : rowData['mdl_id_fk'],
                    okng : okng
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                SelectDom.addSelectArr(domObj.dialogs.$gradeDialog_gradeGroupSel, outObj.oary, "gd_grp", "gd_grp", "", true);
            }else{
            	return false;
            }
            if(!toolFunc.iniPrdGradeListInfo()){
            	return false;
            }
            return true;
        },
        /**
         * 根据等级组获取等级
         */
        iniPrdGradeListInfo: function () {
        	var rowIds = domObj.grids.$prodListGrd.jqGrid('getDataIDs');
    		if(rowIds.length <= 0){
    			showErrorDialog("","请输入需要出账的屏体代码，并按回车键获取屏体信息！");
    			return false;
    		}
            var okng = "NG";
            if(domObj.$radioOK.attr("checked") == "checked") {
                okng = "OK";
            }
    		var rowData = domObj.grids.$prodListGrd.jqGrid('getRowData',rowIds[0]);
            var iary = {
                mdl_id : rowData['mdl_id_fk'],
                okng : okng
            }
            if ($.trim(domObj.dialogs.$gradeDialog_gradeGroupSel.val())) {
                iary.gd_grp = $.trim(domObj.dialogs.$gradeDialog_gradeGroupSel.val());
            }
            var inObj = {
                trx_id: VAL.T_FBPMDLDEF,
                action_flg: "N",
                iary: [iary]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	setGridInfo(outObj.oary, "#gradeDialog_gradeListGrd");
            }else{
            	return false;
            }
            return true;
        },
        queryPrdInfo : function(){
            domObj.$radioOK.val("OK");
            domObj.$prdGradeSel.val("OK");
        	var prd_seq_id = $.trim(domObj.$prdSeqIdTxt.val());
        	if(!prd_seq_id){
                showErrorDialog("", "请输入屏体代码");
                return false;
        	}
            var wo_id = $.trim(domObj.$woIdSel.val());
            var ope_id = $.trim(domObj.$opeIdSel.val());

            var inObj = {
                trx_id     : VAL.T_FIPINQSHT,
                action_flg : "Q",
                prd_seq_id : prd_seq_id
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                //检查工艺路线
                var crPathIdFk = outObj.cr_path_id_fk;
                var crPathVerFk = outObj.cr_path_ver_fk;
                var iary1 = {
                    path_id : crPathIdFk,
                    path_ver : crPathVerFk
                }
                var inObj1 = {
                    trx_id     : VAL.T_FBPBISPTH,
                    action_flg : "Q",
                    iaryA : [iary1]
                }
                var outObj1 = comTrxSubSendPostJson(inObj1);
                if (outObj1.rtn_code == VAL.NORMAL) {
                    if(outObj1.oaryA != null && outObj1.oaryA[0].path_cate == 'RWK'){
                        showErrorDialog("","该玻璃当前工艺路线为RWK路线，需在重工过账界面出账！");
                        return false;
                    }
                }

                setGridInfo(outObj, "#prodListGrd");
                if(outObj.prd_stat !== "INPR"){
                    showErrorDialog("", "屏体状态不正确，必须为[INPR],当前状态为[" + outObj.prd_stat + "]");
                    return false;
            	}else if(outObj.cr_toolg_id_fk == "$FMA"||outObj.cr_toolg_id_fk == "$FQC"||outObj.cr_toolg_id_fk == "$MPK"){
                    showErrorDialog("", "屏体站点为[" + outObj.ope_id_fk + "]，请去该站点出账");
                    return false;
                }else if(outObj.ope_id_fk !== ope_id){
                    showErrorDialog("", "屏体站点代码不匹配，屏体站点为[" + outObj.ope_id_fk + "]");
                    return false;
            	}else if(outObj.wo_id_fk !== wo_id){
                    showErrorDialog("", "屏体工单代码不匹配，屏体工单为[" + outObj.wo_id_fk + "]");
                    return false;
            	}
            	/*********************获取屏体绑定物料信息**********************/
            	toolFunc.queryPrdMtrlInfo(prd_seq_id);
            	//默认OK
            	domObj.$radioOK.attr("checked",true);
            	btnFunc.radio_ok_func();
                /*********************初始化不良信息**********************/
        		SelectDom.initWithSpace(domObj.dialogs.$defectDialog_defectTypeSel);
        		domObj.dialogs.$defectDialog_defectListGrd.jqGrid("clearGridData");
                toolFunc.iniDefectInfo();
            }else{
            	return false;
            }
        },
        queryPrdMtrlInfo : function(prd_seq_id){
        	var inObj = {
                trx_id     : VAL.T_MIPINQMTRL,
                action_flg : "Q",
                prd_seq_id : prd_seq_id
            };
        	var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
            	setGridInfo(outObj.oary, "#mtrlListGrd");
            }
        },
        addSelectOpe:function($selectDom,arr,valProp,txtProp1,txtProp2,firstSpace){
            var i,options;
            if(!arr){
                return false;
            }
            if(!$.isArray(arr)){
                arr = [arr];
            }
            $selectDom.empty();
            if(firstSpace === true){
                $selectDom.append("<option ></option>");
            }
            txtProp1 = (typeof(txtProp1)==="undefined" ? valProp :txtProp1);
            txtProp2 = (typeof(txtProp2)==="undefined" ? valProp :txtProp2);
            /***
             * 提高执行效率，避免多次给Select添加元素
             * 使用array.join("") 代替"+"拼接字符串
             */
            options = [];
            for(i=0;i<arr.length;i++){
                if(arr[i].toolg_id=='$FMA'||arr[i].toolg_id=='$FQC'||arr[i].toolg_id=='$MPK'){
                    continue;
                };
                options[i] = "<option value ="+ arr[i][valProp] +">" + arr[i][txtProp1]+":"+ arr[i][txtProp2]+ "</option>";
            }
            $selectDom.append(options.join(""));
            $selectDom.select2({
                theme : "bootstrap"
            });
        },
    };
    
    /**
     * All button click function
     * @type {Object}
     */
    var btnFunc = {
    	move_out_func : function(){
    		var prd_judge;
        	var rowIds = domObj.grids.$prodListGrd.jqGrid('getDataIDs');
    		if(rowIds.length <= 0){
    			showErrorDialog("","请输入需要出账的屏体代码，并按回车键获取屏体信息！");
    			return false;
    		}
    		var rowData = domObj.grids.$prodListGrd.jqGrid('getRowData',rowIds[0]);

            var tool_id = $.trim(domObj.$toolIdSel.val());
            if(!tool_id){
                showErrorDialog("", "请选择设备代码");
                return false;
            }
            var woId = domObj.$woIdSel.val();
            var lineId = domObj.$bayIdSel.val();
            var opeId = domObj.$opeIdSel.val();

            var inObj1 = {
                trx_id     : VAL.T_MSPLINEWO,
                evt_usr    : VAL.EVT_USER,
                action_flg : "Q",
                line_id : lineId,
                wo_id : woId,
                ope_id: opeId,
                valid_flg : 'Y'
            };
            var outObj1 = comTrxSubSendPostJson(inObj1);
            if (outObj1.rtn_code == VAL.NORMAL) {
                if (outObj1.oary != null && outObj1.oary.length > 0) {
                    //获取屏体判定，NG时必须选择重工工艺路线
                    if(domObj.$radioOK.attr("checked") == "checked") {
                        prd_judge = "OK";outObj1
                    }else{
                        prd_judge = "NG";
                    }

                    if(prd_judge == "NG"){
                        if(!$.trim(domObj.$reworkSel.val())){
                            showErrorDialog("", "请选择重工工艺");
                            return false;
                        }
                        if(!$.trim(domObj.$defectCodeSel.val())){
                            showErrorDialog("", "请选择不良代码");
                            return false;
                        }
                    }

                    //获取屏体等级
                    var prd_grade = $.trim(domObj.$prdGradeSel.val());
                    if(!prd_grade){
                        showErrorDialog("", "请选择屏体等级");
                        return false;
                    }

                    var rwkAry = $.trim(domObj.$reworkSel.val()).split("@");
                    var inObj = {
                        trx_id     : VAL.T_FPPMOVEOUT,
                        evt_usr    : VAL.EVT_USER,
                        action_flg : "O",
                        opi_ope_flg: "Y",
                        iary       : [{
                            prd_seq_id : rowData['prd_seq_id'],
                            tool_id_fk : tool_id,
                            prd_judge : prd_judge,
                            prd_grade : prd_grade,
                            rwk_route_id : rwkAry[0],
                            rwk_route_ver : rwkAry[1],
                            rwk_id : rwkAry[2],
                            rwk_typ : rwkAry[3],
                            defect_code : $.trim(domObj.$defectCodeSel.val()),
                            sht_ope_msg : $.trim(domObj.$remarkTxt.val())
                        }]
                    };
                    var outObj = comTrxSubSendPostJson(inObj);
                    if (outObj.rtn_code == VAL.NORMAL) {
                        domObj.grids.$prodListGrd.jqGrid("clearGridData");
                        domObj.grids.$mtrlListGrd.jqGrid("clearGridData");
                        showMessengerSuccessDialog("出账成功！",1);
                        domObj.$prdSeqIdTxt.val("");
                        domObj.$prdSeqIdTxt.focus();
                    }
                }else{
                    showErrorDialog("","工单"+woId+"未否绑定线别，站点!或未激活！重新选择！");
                }
            }

    	},
        clean_func: function () {
        	iniContorlData();
            domObj.grids.$prodListGrd.jqGrid("clearGridData");
            domObj.grids.$mtrlListGrd.jqGrid("clearGridData");
            domObj.dialogs.$defectDialog_defectListGrd.jqGrid("clearGridData");
            domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid("clearGridData");
        },
        radio_ok_func : function(){
        	domObj.$reworkSel.attr(VAL.DISABLED_ATTR);
            domObj.$defectCodeSel.attr(VAL.DISABLED_ATTR);
            domObj.$remarkTxt.attr(VAL.DISABLED_ATTR);
            /**************清空重工工艺、不良代码、备注信息****************/
            SelectDom.initWithSpace(domObj.$reworkSel);
            SelectDom.initWithSpace(domObj.$defectCodeSel);
            domObj.$remarkTxt.val("");
            /**********************初始化等级信息*************************/
        	toolFunc.iniGradeInfo();
        },
        radio_ng_func : function(){
        	domObj.$reworkSel.attr(VAL.ENABLED_ATTR);
            domObj.$defectCodeSel.attr(VAL.ENABLED_ATTR);
            domObj.$remarkTxt.attr(VAL.ENABLED_ATTR);
            /**************清空重工工艺、不良代码、备注信息****************/
            SelectDom.initWithSpace(domObj.$reworkSel);
            SelectDom.initWithSpace(domObj.$defectCodeSel);
            domObj.$remarkTxt.val("");
            /**********************初始化等级信息*************************/
            if(!toolFunc.iniGradeInfo()){
            	return false;
            }
            /*******************初始化重工工艺路线*********************/
            toolFunc.iniReworkPathSel();
        },
        defect_sure_func : function(){
        	var rowId = domObj.dialogs.$defectDialog_defectListGrd.jqGrid('getGridParam','selrow');
        	if(!rowId){
        		showErrorDialog("", "请选择不良代码");
        		return false;
        	}
        	var rowData = domObj.dialogs.$defectDialog_defectListGrd.jqGrid("getRowData", rowId);
        	SelectDom.initWithValTxt(domObj.$defectCodeSel, rowData['data_id'], rowData['data_id']);
        	domObj.dialogs.$defectDialog.modal('hide');
        },
        grade_sure_func : function(){
        	var rowId = domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid('getGridParam','selrow');
        	if(!rowId){
        		showErrorDialog("", "请选择屏体等级");
        		return false;
        	}
        	var rowData = domObj.dialogs.$gradeDialog_gradeListGrd.jqGrid("getRowData", rowId);
        	SelectDom.initWithValTxt(domObj.$prdGradeSel, rowData['prd_grade'], rowData['prd_grade']);
        	domObj.dialogs.$gradeDialog.modal('hide');
        }
    };
    
    /**
     * Bind button click action
     */
    var iniButtonAction = function(){
        domObj.buttons.$move_out_btn.click(function(){
        	btnFunc.move_out_func();
        });
        domObj.buttons.$clean_btn.click(function(){
        	btnFunc.clean_func();
        });
        domObj.$radioOK.click(function(){
        	btnFunc.radio_ok_func();
        });
        domObj.$radioNG.click(function(){
        	btnFunc.radio_ng_func();
        });
        domObj.$defectCodeSel.on("select2:opening",function(e){
            toolFunc.iniDefectDialogFunc();
        });
        domObj.$prdGradeSel.on("select2:opening",function(e){
            toolFunc.iniGradeDialogFunc();
        });
    };
    
    /**
     * Ini contorl's data
     */
    var iniContorlData = function(){
    	$("input").val("");
    	SelectDom.initWithSpace($("select"));
    	domObj.$radioOK.attr("checked","checked");
    	domObj.$reworkSel.attr(VAL.DISABLED_ATTR);
        domObj.$defectCodeSel.attr(VAL.DISABLED_ATTR);
        domObj.$remarkTxt.attr(VAL.DISABLED_ATTR);
    	toolFunc.initBayArea();
        toolFunc.iniOpeIdSel();
        toolFunc.iniToolIdSel();
        toolFunc.initWoCate();
        toolFunc.iniWoIdSel();
    };
    
    var otherActionBind = function(){
        //Stop from auto commit
        $("form").submit(function(){
            return false;
        });

        $(window).resize(function() {
        	toolFunc.resizeFnc();
        });
        
        domObj.$bayIdSel.change(function(){
        	toolFunc.iniToolIdSel();
        });
        
        domObj.$opeIdSel.change(function(){
        	toolFunc.iniToolIdSel();
        });
        
        domObj.$woCateSel.change(function(){
        	toolFunc.iniWoIdSel();
        });

        domObj.$prdSeqIdTxt.keydown(function(event){
            if(event.keyCode==13){
            	toolFunc.queryPrdInfo();
            }
        });
        
        domObj.dialogs.$gradeDialog_gradeGroupSel.change(function(){
        	toolFunc.iniPrdGradeListInfo();
        });
        
        domObj.dialogs.$defectDialog_defectTypeSel.change(function(){
        	toolFunc.iniDefectListInfo();
        });
    };
    
    /**
     * Ini view, data and action bind
     */
    var initializationFunc = function(){
    	iniGridInfo();
    	toolFunc.resizeFnc();
        iniContorlData();
        iniButtonAction();
        otherActionBind();
    };
    
    initializationFunc();
});
